package com.lxh.student.bo;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lxh.student.common.Const;
import com.lxh.student.dao.RcAdminMapper;
import com.lxh.student.dao.RcStudentMapper;
import com.lxh.student.dao.RcTeacherMapper;
import com.lxh.student.entity.RcAdmin;
import com.lxh.student.entity.RcStudent;
import com.lxh.student.entity.RcTeacher;
import com.lxh.student.vo.input.LoginInputVo;
import com.lxh.student.vo.output.LoginInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginBo {
    @Autowired
    private RcStudentMapper studentMapper;
    @Autowired
    private RcTeacherMapper teacherMapper;
    @Autowired
    private RcAdminMapper adminMapper;

    public LoginInfoVo getUserByName(LoginInputVo inputVo){
        LoginInfoVo infoVo =null;
        if(inputVo.getType() == Const.UserType.STUDENT){
            RcStudent student_number = studentMapper.selectOne(
                    new QueryWrapper<RcStudent>().eq("student_number", inputVo.getUsername()));
            //查询到数据
            if(student_number!=null){
                //数据封装到LoginInfoVo 方便后续业务处理
                infoVo = new LoginInfoVo(
                        student_number.getStudentId(),
                        student_number.getStudentName(),
                        student_number.getStudentPassword(),
                        Const.UserType.STUDENT
                );
            }
        }else if(inputVo.getType() == Const.UserType.TEACHER){

            RcTeacher teacher_number = teacherMapper.selectOne(
                    new QueryWrapper<RcTeacher>().eq("teacher_number", inputVo.getUsername()));
            //查询到数据
            if(teacher_number!=null){
                //数据封装到LoginInfoVo 方便后续业务处理
                infoVo = new LoginInfoVo(
                        teacher_number.getTeacherId(),
                        teacher_number.getTeacherName(),
                        teacher_number.getTeacherPassword(),
                        Const.UserType.TEACHER
                );
            }
        }else if(inputVo.getType() == Const.UserType.ADMIN){
            RcAdmin admin_number = adminMapper.selectOne(
                    new QueryWrapper<RcAdmin>().eq("admin_username", inputVo.getUsername()));
            //查询到数据
            if(admin_number!=null){
                //数据封装到LoginInfoVo 方便后续业务处理
                infoVo = new LoginInfoVo(
                        admin_number.getAdminId(),
                        admin_number.getAdminUsername(),
                        admin_number.getAdminPassword(),
                        Const.UserType.ADMIN
                );
            }
        }

        return infoVo;
    }


}
